package ysq.xyg.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import ysq.xyg.dao.WebCooperateDao;
import ysq.xyg.model.WebCooperate;
import ysq.xyg.service.WebCooperateService;

import javax.annotation.Resource;
import java.util.List;


@Service("webCooperateService")
public class WebCooperateServiceImpl extends BaseServiceImpl<WebCooperate> implements WebCooperateService {

    @Resource
    private WebCooperateDao webCooperateDao;
    @Autowired
    public void setpictureDao(WebCooperateDao webCooperateDao) {
        this.baseDao = webCooperateDao;
    }

    @Override
    public PageInfo<WebCooperate> page(WebCooperate webCooperate, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        PageHelper.orderBy("sort desc");
        return new PageInfo<WebCooperate>(list(webCooperate));
    }

    @Override
    public List<WebCooperate> list(WebCooperate webCooperate) {
        // 通用Example查询
        Example example = new Example(WebCooperate.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotEmpty(webCooperate.getName())) {
            criteria.andLike("name", "%"+webCooperate.getName()+"%");
        }
        example.setOrderByClause("sort desc");
        List<WebCooperate> list = webCooperateDao.selectByExample(example);
        return list;
    }
}
